package com.lb.activity.mapper;

import com.lb.activity.po.ExaminePermission;
import com.lb.activity.po.ExamineRolePermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author liubin
 */
public interface ExamineRolePermissionMapper extends Mapper<ExamineRolePermission> {
    @Select(" select permissionid from examine_role_permission where roleid = #{roleId} ")
    List<Long> selectPermissionByRoleId(Long roleId);

    @Delete("delete from examine_role_permission where roleid = #{id} ")
    void removeByRoleId(Long id);

    @Insert({"<script> INSERT INTO examine_role_permission (ID,ROLEID, PERMISSIONID,STATUS) " +
            "values " +
            "<foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\"> "+
            "      (#{item.id,jdbcType=BIGINT},#{item.roleid,jdbcType=BIGINT},#{item.permissionid,jdbcType=BIGINT},#{item.status,jdbcType=BIGINT})\n" +
            "</foreach> </script>"})
    void batchSave(List<ExamineRolePermission> storeRolePermissions);

    @Select(" select * from examine_role_permission rp,examine_permission p where rp.roleid = #{roleId} and rp.permissionid = p.ID and p.name_code = #{dept}")
    ExamineRolePermission selectPermissionsByRoleIdAndCode(@Param("roleId") Long roleId, @Param("dept") String dept);
}
